package com.yuwubao.hz_International.entities.repository;

import com.yuwubao.hz_International.entities.ConsumerEntity;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by yangyu on 2018/1/25.
 */
public interface ConsumerRepository extends JpaRepository<ConsumerEntity, Integer>, JpaSpecificationExecutor<ConsumerEntity> {

    ConsumerEntity findByPhone(String phone);

    ConsumerEntity findByPhoneAndPassword(String phone, String pwd);

    ConsumerEntity findByName(String consumerName);

    @Query(value = "SELECT sum(welfareMoney) FROM consumer", nativeQuery = true)
    BigDecimal getAllWelfare();

    @Query(value = "SELECT * FROM consumer WHERE welfareMoney > 0", nativeQuery = true)
    List<ConsumerEntity> hasWelfareUser();

    @Query(value = "SELECT * FROM consumer WHERE giftMoney >0", nativeQuery = true)
    List<ConsumerEntity> hasGiftUser();

    @Query(value = "SELECT * from consumer where bonous>0",nativeQuery = true)
    List<ConsumerEntity> hasBonousUser();
}
